package com.study.dataStructure.set;

import java.util.HashSet;
import java.util.Set;

/**
 * @PACKAGE_NAME: com.study.dataStructure.Set
 * @CLASS_NAME: TestHashSetMethodsInCollection
 * @USER: kagura
 * @Description TODO
 * @Date 2020/12/12 12:29 上午
 * @MONTH_NAME_FULL: 十二月
 * @DAY: 12
 * @DAY_NAME_FULL: 星期六
 * @PROJECT_NAME: Study
 **/
public class TestHashSetMethodsInCollection {
    public static void main(String[] args) {
        // create set
        Set<String> set1 = new HashSet<>();

        // add strings to set1
        set1.add("重庆");
        set1.add("北京");
        set1.add("天津");
        set1.add("上海");

        System.out.println("set1 is : " + set1);
        System.out.println(set1.size() + " elements in set1");

        // delete a string from set1
        set1.remove("上海");
        System.out.println("\nset1 is : " + set1);
        System.out.println(set1.size() + " elements in set1");

        // create set2
        Set<String> set2 = new HashSet<>();

        // add strings to set2
        set2.add("重庆");
        set2.add("成都");
        set2.add("武汉");
        System.out.println("\nset2 is : " + set2);
        System.out.println(set2.size() + " elements in set2");

        System.out.println("\n西安在set2? " + set2.contains("西安"));

        set1.addAll(set2);
        System.out.println("\nafter adding set2 to set1, set1 is : " + set1);
        System.out.println(set1.size() + " elements in set1");

        set1.removeAll(set2);
        System.out.println("\nafter removing set2 from set1, set1 is : " + set1);
        System.out.println(set1.size() + " elements in set1");

        set1.retainAll(set2);
        System.out.println("\nafter retaining common elements in set2 and set2, set1 is : " + set1);
        System.out.println(set1.size() + " elements in set1");
    }
}
